﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Temp.Database;
using Temp.Model;

namespace Temp.Controller
{
    class NPCDialogueController
    {
        private SQLiteFactory sqlf;
        private SQLite.SQLiteConnection conn;

        public NPCDialogueController()
        {
            sqlf = new SQLiteFactory();
        }

        public List<string> getDialogue(string storyNode, string npcName)
        {
            conn = sqlf.getConnection();
            System.Diagnostics.Debug.WriteLine("story Node:" + storyNode + "npc Name:" + npcName);
            List<NPCDialogue> dList = conn.Query<NPCDialogue>("SELECT * FROM NPCDialogue WHERE storyNode = ? AND npcName = ?", storyNode, npcName).ToList();

            if (dList.Count == 0)
            {
                dList = conn.Query<NPCDialogue>("SELECT * FROM NPCDialogue WHERE storyNode = ? AND npcName = ?", "DEFAULT", npcName).ToList();
            }

            List<string> dialogueList = new List<string>();
            foreach (NPCDialogue n in dList)
            {
                dialogueList.Add(n.dialogue);
            }
            conn.Close();
            return dialogueList;
        }

        public List<string> getSpeakers(string storyNode, string npcName) {
            conn = sqlf.getConnection();
            System.Diagnostics.Debug.WriteLine("story Node:" + storyNode + "npc Name:" + npcName);
            List<NPCDialogue> dList = conn.Query<NPCDialogue>("SELECT * FROM NPCDialogue WHERE storyNode = ? AND npcName = ?", storyNode, npcName).ToList();

            if (dList.Count == 0)
            {
                dList = conn.Query<NPCDialogue>("SELECT * FROM NPCDialogue WHERE storyNode = ? AND npcName = ?", "DEFAULT", npcName).ToList();
            }

            List<string> speakerList = new List<string>();
            foreach (NPCDialogue n in dList)
            {
                speakerList.Add(n.speaker);
            }
            conn.Close();
            return speakerList;
        }
    }
}
